package cn.jinhe.doc.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.jinhe.doc.base.DaoSupportImpl;
import cn.jinhe.doc.domain.Department;
import cn.jinhe.doc.service.DepartmentService;
@Service
@Transactional
public class DepartmentServiceImpl extends DaoSupportImpl<Department> implements DepartmentService{

//	@Resource
//	private DepartmentDao departmentDao;
//
//	public void delete(Long id) {
//		departmentDao.delete(id);
//	}
//
//	public List<Department> findAll() {
//		return departmentDao.findAll();
//	}
//
//	public Department getById(Long id) {
//		return departmentDao.getById(id);
//	}
//
//	public void save(Department model) {
//		departmentDao.save(model);
//	}
//
//	public void update(Department department) {
//		departmentDao.update(department);
//	}

	@Resource
	private SessionFactory sessionFactory;
	 
	@SuppressWarnings("unchecked")
	public List<Department> findTopList(){
		return sessionFactory.getCurrentSession().createQuery(//
				"FROM Department d WHERE d.parent.id IS NULL")				
				.list();
		
	}
	
	@SuppressWarnings("unchecked")
	public List<Department> findChildren(Long parentId){
		return sessionFactory.getCurrentSession().createQuery(//
				"FROM Department d WHERE d.parent.id=?")
				.setParameter(0, parentId)
				.list();
		
	}
	
	
}
